/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * SES100.java
 *
 * Created on 2011-7-5, 13:21:55
 */
package seso;

import java.awt.Graphics;
import javax.swing.JLabel;


import java.awt.Color;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import org.jdesktop.application.Task;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.RollbackException;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import org.jdesktop.beansbinding.AbstractBindingListener;
import org.jdesktop.beansbinding.Binding;
import org.jdesktop.beansbinding.PropertyStateEvent;
import javax.swing.*;
import java.awt.*;

import java.sql.*;

/**
 *
 * @author Administrator
 */
//public class SES100 extends javax.swing.JDialog {
public class SES130B extends MaintDialog {

    private JLabel[] headerJLabel;
    private HeaderJSeparator[] headerJSeparator;
    private int headerXAdjust = 1;
    private boolean isFirstTime = true;
    private Color tableBackgroundColor = new Color(235, 238, 241);

    /** Creates new form SES130 */
    public SES130B(javax.swing.JFrame parent, boolean modal) {
        super(parent, modal);

        initComponents();
        isBrowseDialog = true;
        refreshToolsBar();

        setProgTitle("SES130/B*", "Import Customer Order");

        initTableHeader();
    }

    private void initTableHeader() {
        headerJLabel = new JLabel[masterTable.getColumnCount()];
        headerJSeparator = new HeaderJSeparator[masterTable.getColumnCount()];

        for (int i = 0; i < masterTable.getColumnCount(); i++) {
            headerJLabel[i] = new JLabel();
            headerJLabel[i].setForeground(Color.WHITE);
            headerJLabel[i].setFont(new Font("Arial", Font.BOLD, 11));
            headerJLabel[i].setText(masterTable.getColumnModel().getColumn(i).getHeaderValue().toString());

            if (headerJLabel[i].getText().equals("Customer Id")) {
                headerJLabel[i].setHorizontalAlignment(JLabel.RIGHT);
            } else {
                headerJLabel[i].setHorizontalAlignment(JLabel.LEFT);
            }
            masterHeader.add(headerJLabel[i]);

            headerJSeparator[i] = new HeaderJSeparator();
            headerJSeparator[i].setForeground(new Color(150, 170, 190));
            headerJSeparator[i].setJTable(masterTable);
            headerJSeparator[i].setIndex(i);

            headerJSeparator[i].setOrientation(SwingConstants.VERTICAL);
            //headerJSeparator[i].setBackground(new Color(204,204,255));
            headerJSeparator[i].setBackground(new Color(192, 192, 192));
            headerJSeparator[i].setCursor(new Cursor(Cursor.E_RESIZE_CURSOR));
            masterHeader.add(headerJSeparator[i]);
        }


    }

    private void RefreshTableHeader() {
        int startPosition = 0;
        int width = 0;
        for (int i = 0; i < masterTable.getColumnCount(); i++) {
            width = this.masterTable.getColumnModel().getColumn(i).getWidth();
            headerJLabel[i].setBounds(headerXAdjust + startPosition + 5, 10, width - 8, 20);

            startPosition = startPosition + width;
            headerJSeparator[i].setBounds(headerXAdjust + startPosition - 1, 8, 2, masterHeader.getHeight() - 10);
        }
    }

    @Override
    public void paint(Graphics g) {

        MoreSetControlsLocationAndSize();
        RefreshTableHeader();

        super.paint(g);
    }

    private void MoreSetControlsLocationAndSize() {

        int width = getWidth(), height = getHeight();

        masterJScrollPane.setBackground(tableBackgroundColor);
        masterJScrollPane.getViewport().setBackground(tableBackgroundColor);
        masterTable.setBackground(tableBackgroundColor);

        rDialogDataAeraPanel.setSize(width, height - 90); //  ToolsBar and StatusBar total margin

        rDlgTableHeaderBackground.setSize(rDialogDataAeraPanel.getWidth() - rDlgTableHeaderBackground.getX() * 2, rDlgTableHeaderBackground.getHeight());

        int tableBottomMargin = 80; // bottom margin
        masterJScrollPane.setLocation(rDlgTableHeaderBackground.getX() + 1, rDlgTableHeaderBackground.getY() + rDlgTableHeaderBackground.getHeight());
        masterJScrollPane.setSize(rDlgTableHeaderBackground.getWidth() - 2, rDialogDataAeraPanel.getHeight() - masterJScrollPane.getY() - tableBottomMargin);
        masterTable.setSize(masterJScrollPane.getWidth(), masterJScrollPane.getHeight());

        masterHeader.setLocation(rDlgTableHeaderBackground.getX(), rDlgTableHeaderBackground.getY());
        masterHeader.setSize(rDlgTableHeaderBackground.getWidth(), rDlgTableHeaderBackground.getHeight());

        bottomNavJPanel.setLocation(10, rDialogDataAeraPanel.getHeight() - 10 - bottomNavJPanel.getHeight());
        bottomNavJPanel.setSize(rDialogDataAeraPanel.getWidth() - bottomNavJPanel.getX() * 2, bottomNavJPanel.getHeight());

        comNavClose.setLocation(0, 0);
        comNavNext.setLocation(bottomNavJPanel.getWidth() - comNavNext.getWidth(), 0);
        comNavPrev.setLocation(comNavNext.getX() - comNavPrev.getWidth(), 0);

        convert2M3CORButton.setLocation(masterJScrollPane.getX() + masterJScrollPane.getWidth() - convert2M3CORButton.getWidth(), convert2M3CORButton.getY());
        checkDataRButton.setLocation(convert2M3CORButton.getX() - checkDataRButton.getWidth() - 20, checkDataRButton.getY());

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        entityManager = java.beans.Beans.isDesignTime() ? null : javax.persistence.Persistence.createEntityManagerFactory("M3G;databaseName=M3ERPPU").createEntityManager();
        europeOrderTextQuery = java.beans.Beans.isDesignTime() ? null : entityManager.createQuery("SELECT e FROM EuropeOrderText e");
        europeOrderTextList = java.beans.Beans.isDesignTime() ? java.util.Collections.emptyList() : org.jdesktop.observablecollections.ObservableCollections.observableList(europeOrderTextQuery.getResultList());
        rDialogDataAeraPanel = new seso.RDialogDataAeraPanel();
        masterHeader = new seso.RPanel();
        rDlgTableHeaderBackground = new seso.RTableHeaderBackground();
        masterJScrollPane = new javax.swing.JScrollPane();
        masterTable = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        bottomNavJPanel = new javax.swing.JPanel();
        comNavClose = new javax.swing.JButton();
        comNavNext = new javax.swing.JButton();
        comNavPrev = new javax.swing.JButton();
        checkDataRButton = new seso.RBgButton();
        convert2M3CORButton = new seso.RBgButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N
        getContentPane().setLayout(null);

        rDialogDataAeraPanel.setName("rDialogDataAeraPanel"); // NOI18N
        rDialogDataAeraPanel.setLayout(null);

        masterHeader.setName("masterHeader"); // NOI18N
        rDialogDataAeraPanel.add(masterHeader);
        masterHeader.setBounds(80, 60, 500, 30);

        rDlgTableHeaderBackground.setName("rDlgTableHeaderBackground"); // NOI18N
        rDialogDataAeraPanel.add(rDlgTableHeaderBackground);
        rDlgTableHeaderBackground.setBounds(10, 50, 820, 52);

        masterJScrollPane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        masterJScrollPane.setName("masterJScrollPane"); // NOI18N

        masterTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        masterTable.setFillsViewportHeight(true);
        masterTable.setName("masterTable"); // NOI18N
        masterTable.setRowHeight(20);
        masterTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        masterTable.setTableHeader(null);

        org.jdesktop.swingbinding.JTableBinding jTableBinding = org.jdesktop.swingbinding.SwingBindings.createJTableBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, europeOrderTextList, masterTable);
        org.jdesktop.swingbinding.JTableBinding.ColumnBinding columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${transNoLine}"));
        columnBinding.setColumnName("Trans No Line");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${errorMessage}"));
        columnBinding.setColumnName("Error Message");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${itemNo}"));
        columnBinding.setColumnName("Item No");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${facility}"));
        columnBinding.setColumnName("Facility");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${season}"));
        columnBinding.setColumnName("Season");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${label}"));
        columnBinding.setColumnName("Label");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${m3Quality}"));
        columnBinding.setColumnName("M3 Quality");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${m3Style}"));
        columnBinding.setColumnName("M3 Style");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${customerDigitalCode}"));
        columnBinding.setColumnName("Customer Digital Code");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${customer}"));
        columnBinding.setColumnName("Customer");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${customerCode}"));
        columnBinding.setColumnName("Customer Code");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${m3Color}"));
        columnBinding.setColumnName("M3 Color");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${sizeList}"));
        columnBinding.setColumnName("Size List");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${quantity}"));
        columnBinding.setColumnName("Quantity");
        columnBinding.setColumnClass(Integer.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${price}"));
        columnBinding.setColumnName("Price");
        columnBinding.setColumnClass(Double.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${barcode}"));
        columnBinding.setColumnName("Barcode");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${rvPoNo}"));
        columnBinding.setColumnName("Rv Po No");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${rvSubCustomerCode}"));
        columnBinding.setColumnName("Rv Sub Customer Code");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${rvDelDateFrom}"));
        columnBinding.setColumnName("Rv Del Date From");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${rvDelDateTo}"));
        columnBinding.setColumnName("Rv Del Date To");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${deliveryType}"));
        columnBinding.setColumnName("Delivery Type");
        columnBinding.setColumnClass(Character.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${itemDescription}"));
        columnBinding.setColumnName("Item Description");
        columnBinding.setColumnClass(String.class);
        columnBinding = jTableBinding.addColumnBinding(org.jdesktop.beansbinding.ELProperty.create("${transactionNo}"));
        columnBinding.setColumnName("Transaction No");
        columnBinding.setColumnClass(String.class);
        columnBinding.setEditable(false);
        bindingGroup.addBinding(jTableBinding);
        jTableBinding.bind();
        masterTable.addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentMoved(java.awt.event.ComponentEvent evt) {
                masterTableComponentMoved(evt);
            }
            public void componentResized(java.awt.event.ComponentEvent evt) {
                masterTableComponentResized(evt);
            }
        });
        masterJScrollPane.setViewportView(masterTable);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(seso.SesoApp.class).getContext().getResourceMap(SES130B.class);
        masterTable.getColumnModel().getColumn(0).setPreferredWidth(120);
        masterTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("masterTable.columnModel.title0")); // NOI18N
        masterTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("masterTable.columnModel.title1")); // NOI18N
        masterTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("masterTable.columnModel.title2")); // NOI18N
        masterTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("masterTable.columnModel.title3")); // NOI18N
        masterTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("masterTable.columnModel.title4")); // NOI18N
        masterTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("masterTable.columnModel.title5")); // NOI18N
        masterTable.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("masterTable.columnModel.title6")); // NOI18N
        masterTable.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("masterTable.columnModel.title7")); // NOI18N
        masterTable.getColumnModel().getColumn(8).setHeaderValue(resourceMap.getString("masterTable.columnModel.title8")); // NOI18N
        masterTable.getColumnModel().getColumn(9).setHeaderValue(resourceMap.getString("masterTable.columnModel.title9")); // NOI18N
        masterTable.getColumnModel().getColumn(10).setHeaderValue(resourceMap.getString("masterTable.columnModel.title10")); // NOI18N
        masterTable.getColumnModel().getColumn(11).setHeaderValue(resourceMap.getString("masterTable.columnModel.title11")); // NOI18N
        masterTable.getColumnModel().getColumn(12).setHeaderValue(resourceMap.getString("masterTable.columnModel.title12")); // NOI18N
        masterTable.getColumnModel().getColumn(13).setHeaderValue(resourceMap.getString("masterTable.columnModel.title13")); // NOI18N
        masterTable.getColumnModel().getColumn(14).setHeaderValue(resourceMap.getString("masterTable.columnModel.title14")); // NOI18N
        masterTable.getColumnModel().getColumn(15).setHeaderValue(resourceMap.getString("masterTable.columnModel.title15")); // NOI18N
        masterTable.getColumnModel().getColumn(16).setHeaderValue(resourceMap.getString("masterTable.columnModel.title16")); // NOI18N
        masterTable.getColumnModel().getColumn(17).setHeaderValue(resourceMap.getString("masterTable.columnModel.title17")); // NOI18N
        masterTable.getColumnModel().getColumn(18).setHeaderValue(resourceMap.getString("masterTable.columnModel.title18")); // NOI18N
        masterTable.getColumnModel().getColumn(19).setHeaderValue(resourceMap.getString("masterTable.columnModel.title19")); // NOI18N
        masterTable.getColumnModel().getColumn(20).setHeaderValue(resourceMap.getString("masterTable.columnModel.title20")); // NOI18N
        masterTable.getColumnModel().getColumn(21).setHeaderValue(resourceMap.getString("masterTable.columnModel.title21")); // NOI18N
        masterTable.getColumnModel().getColumn(22).setHeaderValue(resourceMap.getString("masterTable.columnModel.title22")); // NOI18N

        rDialogDataAeraPanel.add(masterJScrollPane);
        masterJScrollPane.setBounds(10, 110, 970, 90);

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setForeground(resourceMap.getColor("jLabel1.foreground")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N
        rDialogDataAeraPanel.add(jLabel1);
        jLabel1.setBounds(12, 30, 80, 15);

        bottomNavJPanel.setName("bottomNavJPanel"); // NOI18N
        bottomNavJPanel.setOpaque(false);
        bottomNavJPanel.setLayout(null);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(seso.SesoApp.class).getContext().getActionMap(SES130B.class, this);
        comNavClose.setAction(actionMap.get("cmdCloseAction")); // NOI18N
        comNavClose.setIcon(resourceMap.getIcon("comNavClose.icon")); // NOI18N
        comNavClose.setBorder(null);
        comNavClose.setBorderPainted(false);
        comNavClose.setContentAreaFilled(false);
        comNavClose.setFocusPainted(false);
        comNavClose.setFocusable(false);
        comNavClose.setName("comNavClose"); // NOI18N
        comNavClose.setPressedIcon(resourceMap.getIcon("comNavClose.pressedIcon")); // NOI18N
        comNavClose.setRolloverIcon(resourceMap.getIcon("comNavClose.rolloverIcon")); // NOI18N
        bottomNavJPanel.add(comNavClose);
        comNavClose.setBounds(0, 0, 88, 28);

        comNavNext.setAction(actionMap.get("comNavNextAction")); // NOI18N
        comNavNext.setIcon(resourceMap.getIcon("comNavNext.icon")); // NOI18N
        comNavNext.setBorder(null);
        comNavNext.setBorderPainted(false);
        comNavNext.setContentAreaFilled(false);
        comNavNext.setFocusPainted(false);
        comNavNext.setFocusable(false);
        comNavNext.setName("comNavNext"); // NOI18N
        comNavNext.setPressedIcon(resourceMap.getIcon("comNavNext.pressedIcon")); // NOI18N
        comNavNext.setRolloverIcon(resourceMap.getIcon("comNavNext.rolloverIcon")); // NOI18N
        bottomNavJPanel.add(comNavNext);
        comNavNext.setBounds(587, 0, 88, 28);

        comNavPrev.setIcon(resourceMap.getIcon("comNavPrev.icon")); // NOI18N
        comNavPrev.setBorder(null);
        comNavPrev.setBorderPainted(false);
        comNavPrev.setContentAreaFilled(false);
        comNavPrev.setFocusPainted(false);
        comNavPrev.setFocusable(false);
        comNavPrev.setName("comNavPrev"); // NOI18N
        comNavPrev.setPressedIcon(resourceMap.getIcon("comNavPrev.pressedIcon")); // NOI18N
        comNavPrev.setRolloverIcon(resourceMap.getIcon("comNavPrev.rolloverIcon")); // NOI18N
        bottomNavJPanel.add(comNavPrev);
        comNavPrev.setBounds(530, 0, 54, 28);

        rDialogDataAeraPanel.add(bottomNavJPanel);
        bottomNavJPanel.setBounds(10, 270, 670, 28);

        checkDataRButton.setAction(actionMap.get("checkDataAction")); // NOI18N
        checkDataRButton.setText(resourceMap.getString("checkDataRButton.text")); // NOI18N
        checkDataRButton.setFocusable(false);
        checkDataRButton.setName("checkDataRButton"); // NOI18N
        rDialogDataAeraPanel.add(checkDataRButton);
        checkDataRButton.setBounds(230, 20, 120, 28);

        convert2M3CORButton.setAction(actionMap.get("convert2M3CORAction")); // NOI18N
        convert2M3CORButton.setText(resourceMap.getString("convert2M3CORButton.text")); // NOI18N
        convert2M3CORButton.setFocusable(false);
        convert2M3CORButton.setName("convert2M3CORButton"); // NOI18N
        rDialogDataAeraPanel.add(convert2M3CORButton);
        convert2M3CORButton.setBounds(440, 20, 130, 28);

        getContentPane().add(rDialogDataAeraPanel);
        rDialogDataAeraPanel.setBounds(0, 71, 1000, 330);

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void masterTableComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_masterTableComponentResized
        RefreshTableHeader();
    }//GEN-LAST:event_masterTableComponentResized

    private void masterTableComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_masterTableComponentMoved
        String paramString = evt.paramString();
        int indexStart = paramString.indexOf("(") + 1;
        int indexEnd = paramString.indexOf(",");

        int newHeaderXAdjust = Integer.parseInt(paramString.substring(indexStart, indexEnd));
        if (newHeaderXAdjust != headerXAdjust) {
            headerXAdjust = newHeaderXAdjust;
            RefreshTableHeader();
        }
    }//GEN-LAST:event_masterTableComponentMoved

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                SES130B dialog = new SES130B(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }

    @Action
    public void comNavCloseAction() {
        this.cmdCloseAction();
    }


    @Action
    public void comNavNextAction() {
        cmdSave(true);
    }

    private void cmdSave(boolean showMessage) {
        entityManager.getTransaction().begin();
        for (int i = 0; i < europeOrderTextList.size(); i++) {
            entityManager.persist(europeOrderTextList.get(i));
        }
        entityManager.getTransaction().commit();
        
        if (showMessage) {
            JOptionPane.showMessageDialog(null, "Data Saved");
        }
    }
    
    
    
    @Action
    public void checkDataAction() {
        if (masterTable.getSelectedRowCount() == 0) {
            return;
        }
        String transactionNO = masterTable.getValueAt(masterTable.getSelectedRow(), masterTable.getColumnCount() - 1).toString();


        String connectionUrl = "jdbc:sqlserver://M3G;databaseName=M3ERP;user=sa;password=sentserver";

        Connection con = null;
        Statement stmt = null;

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);

            String SQL = "M3ERP..usp_CheckEOT '" + transactionNO + "'";
            stmt = con.createStatement();
            stmt.execute(SQL);
            
            SQL = "Update ETCOH set status = 'Checking' Where TransactionNo = '" + transactionNO  + "'";
            stmt.execute(SQL);
            
        } catch (Exception exp) {
            exp.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (Exception e) {
                }
            }
        }

        cmdRefreshAction();
        JOptionPane.showMessageDialog(null, "Completed");
    }

    @Action
    public void convert2M3CORAction() {
        
        if (masterTable.getSelectedRowCount() == 0) {
            return;
        }
        String transactionNO = masterTable.getValueAt(masterTable.getSelectedRow(), masterTable.getColumnCount() - 1).toString();


        String connectionUrl = "jdbc:sqlserver://M3G;databaseName=M3ERP;user=sa;password=sentserver";

        Connection con = null;
        Statement stmt = null;
        String SQL;

        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);

            stmt = con.createStatement();

            SQL = "Delete M3ERP..M3ShOrderSKU";
            stmt.execute(SQL);

            SQL = "M3ERP..usp_Copy2M3COSKU '" + transactionNO + "'";
            stmt.execute(SQL);

            SQL = "Update ETCOH set status = 'Imported' Where TransactionNo = '" + transactionNO  + "'";
            stmt.execute(SQL);
            

        } catch (Exception exp) {
            exp.printStackTrace();
        } finally {
            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                }
            }
            if (con != null) {
                try {
                    con.close();
                } catch (Exception e) {
                }
            }
        }


        String cmd = "D:\\wfoe\\gtms2m3XM.exe OIS100MI " + Integer.toString(1);
        Runtime rn = Runtime.getRuntime();
        Process p = null;
        try {
            //p = rn.exec("\"D:/wfoe/m3demo.exe\"");
            p = rn.exec(cmd);
        } catch (Exception e) {
            System.out.println("Error exec!");
        }

        JOptionPane.showMessageDialog(null, "Task Commited");
        showGeneratedCO();
    }

    private void showGeneratedCO() {

        try { Thread.sleep(1000);} catch (Exception ignore) {}
        
        String connectionUrl = "jdbc:sqlserver://M3G;databaseName=M3ERP;user=sa;password=sentserver";

        Connection con = null;
        Statement stmt = null;
        ResultSet rs = null;
        String SQL;


        try {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            con = DriverManager.getConnection(connectionUrl);

            stmt = con.createStatement();

            SQL = "Select top 1 CoNo, OrderNo From  M3ERP..M3ShOrderSKU";
            rs = stmt.executeQuery(SQL);

            if (rs.next()) {
                JOptionPane.showMessageDialog(null, "Generated CO No : " + rs.getString("CoNo"));
            } else {
                JOptionPane.showMessageDialog(null, "Generate CO FAILED");
            }

        } catch (Exception exp) {
            exp.printStackTrace();
        } finally {

            if (rs != null) {
                try {
                    rs.close();
                } catch (Exception e) {
                }
            }

            if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception e) {
                }
            }

            if (con != null) {
                try {
                    con.close();
                } catch (Exception e) {
                }
            }
        }


    }

    @Override
    public void cmdRefreshAction() {

        super.cmdRefreshAction();

        java.util.Collection data = europeOrderTextQuery.getResultList();
        for (Object entity : data) {
            entityManager.refresh(entity);
        }
        europeOrderTextList.clear();
        europeOrderTextList.addAll(data);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel bottomNavJPanel;
    private seso.RBgButton checkDataRButton;
    private javax.swing.JButton comNavClose;
    private javax.swing.JButton comNavNext;
    private javax.swing.JButton comNavPrev;
    private seso.RBgButton convert2M3CORButton;
    private javax.persistence.EntityManager entityManager;
    private java.util.List<seso.EuropeOrderText> europeOrderTextList;
    private javax.persistence.Query europeOrderTextQuery;
    private javax.swing.JLabel jLabel1;
    private seso.RPanel masterHeader;
    private javax.swing.JScrollPane masterJScrollPane;
    private javax.swing.JTable masterTable;
    private seso.RDialogDataAeraPanel rDialogDataAeraPanel;
    private seso.RTableHeaderBackground rDlgTableHeaderBackground;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables
}
